
function getSelectId(lv) {
    id = '';
    switch (lv){
        case 0:
            id = "province";
            break;
        case 1:
            id = "city";
            break;
        case 2:
            id = "village";
    }
    return id ;
}

function changeSelectBankType() {

    father = document.getElementById("categorySelect");
    slected = father.selectedIndex;
    category = father.children[0].children[slected].text;

    xmlhttp=new XMLHttpRequest();
    // 获取被选择的城市的Id
    xmlhttp.open("GET","/ajax/getSuperiorDepartment?category="+category,true);
    xmlhttp.onreadystatechange = function () {
        $('select#SuperiorDepartment').prev().children('a').children('span').text(" ");
        father = document.getElementById('SuperiorDepartment').children[0];
        while(father.children.length>0)
            father.removeChild(father.children[0]);
        res = xmlhttp.response;
        res = JSON.parse(res);
        father.label = category;
        for (i = 0;i<res.length;i++){
            te = new Option();
            te.value = res[i].id;
            te.text = res[i].name;
            father.appendChild(te);
        }
    };
    xmlhttp.send();
}

function changeSelectArea(father,na) {
    father.attr('name','regionId')
    if (na){
        na.prev().children('a').children('span').text(" ");
    }
    cityId = father.val();
    xmlhttp=new XMLHttpRequest();
    // 获取被选择的城市的Id
    xmlhttp.open("GET","/ajax/getCity?areaId="+cityId,true);
    xmlhttp.onreadystatechange = function () {
        if(na===null)
            return;
        na.empty();
        res = xmlhttp.response;
        res = JSON.parse(res);
        for (i = 0;i<res.length;i++){
            te = new Option();
            te.value = res[i].id;
            te.text = res[i].val;
            na.append($('<option>').text(res[i].val).val(res[i].id))
        }
    };
    xmlhttp.send();
}
function freshSelect(father){
    if (father.hasClass('areaSelect')){
        if (father.attr('id')==='province'){
            n = $('select#city');
            $('select#village').prev().children('a').children('span').text(" ");
        }else if (father.attr('id')==='city'){
            n = $('select#village')
        }else{
            n = null;
        }
        $('select[name$="regionId"]').removeAttr('name');
        changeSelectArea(father,n);
    }
}